Welcome to the PS2010 Code Bank. Here you will find a collection of the R code used for all data analyses covered across the module. Use the menu on the left hand side to navigate.

Basics

Install and Load Packages


Install a package

install.packages(NULL)
install.packages("tidyverse")

Change NULL to the name of the package.


Load a package

library(NULL)
library(tidyverse)

Change NULL to the name of the package.


Importing Data

Set the Working Directory

setwd(NULL)
setwd(C:/Users/username/documents)

Change NULL to the folder path.

Remember you can also set the working directory using the menu options:

Session -> Set Working Directory -> Choose Directory


Check the Working Directory

getwd()

This will tell you the current working directory.


Import Data

mydata = read_csv(NULL)
mydata = read_csv("experiment_data.csv")

mydata is the object that we save the data under. You can call it whatever you like.

Change NULL to the name of the file.

Remember to add “.csv” at the end of the filename.

R only reads .csv data files.

Note: read_csv() requires the tidyverse package.


Describing Data

T-tests

One-Way ANOVA

Factorial ANOVA